Skip to content

Conversation

djangoliv
Copy link

The kernelspec is now determinated with the type of the first code cell.

I want to generate notebooks with different kernel.

@djangoliv
Copy link
Author

djangoliv commented Feb 8, 2022

There is a problem: 'jupyter_lang_synonyms' is broken. I will have a look.

The kernelspec is now determinated with the type of the first code cell
@djangoliv djangoliv force-pushed the support-defferent-languages branch from 28658c9 to 5e19030 Compare February 9, 2022 08:46
@mmcky mmcky requested a review from Copilot August 19, 2025 01:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the kernelspec determination logic to support different programming languages in Jupyter notebooks. Instead of setting the kernelspec at document level based on a default language, it now determines the kernelspec dynamically based on the language of the first code cell encountered.

  • Moved kernelspec metadata setting from document level to literal block level
  • Added language synonym handling for the first code cell
  • Removed static kernelspec assignment in favor of dynamic determination

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

# markup instead.
if self.nodelang != self.langTranslator.translate(self.lang):
# Update metadata
if self.jupyter_kernels is not None and not self.output.metadata:
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition not self.output.metadata will be false if metadata exists but is empty (e.g., an empty dict). This could prevent kernelspec updates for subsequent code cells. Consider using a more specific check like tracking whether kernelspec has been set.

Copilot uses AI. Check for mistakes.

self.warn(
"Invalid jupyter kernels. "
"jupyter_kernels: {}, lang: {}"
.format(self.jupyter_kernels, self.nodelang))
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying self.nodelang here could have unintended side effects since this variable appears to represent the language of the current node. Consider using a separate variable for the kernelspec language determination.

Copilot uses AI. Check for mistakes.

self.jupyter_kernels[self.nodelang]["kernelspec"]
self.output.metadata["filename"] = self.source_file_name.split("/")[-1]
self.output.metadata["title"] = self.title
except:
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a bare except: clause catches all exceptions including system exits and keyboard interrupts. Consider catching specific exceptions like KeyError or AttributeError instead.

Suggested change
except:
except (KeyError, AttributeError, TypeError):

Copilot uses AI. Check for mistakes.

@mmcky
Copy link
Contributor

mmcky commented Aug 19, 2025

@djangoliv thanks for your PR. Sorry this repo has been unmaintained for too long. Is this still an issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants